package main

import (
	"fmt"
	"strings"
	"unicode/utf8"
)

func main() {
	// 每个中文占据的三字节 UTF8
	s := "我是你爸爸"
	fmt.Println(len(s))
	fmt.Printf("%X\n", []byte(s))
	for _, b := range []byte(s) {
		fmt.Printf("%X ", b)
	}
	fmt.Println()
	for i, ch := range s { // ch is a rune
		// 对s进行解码，将utf8编码转换成unicode编码的ch
		fmt.Printf("(%d %X)", i, ch)
	}
	fmt.Println()
	fmt.Println("Rune count:", utf8.RuneCountInString(s))
	bytes := []byte(s)
	for len(bytes) > 0 {
		ch, size := utf8.DecodeRune(bytes)
		bytes = bytes[size:]
		fmt.Printf("%c", ch)
	}
	fmt.Println()
	for i, ch := range []rune(s) {
		fmt.Printf("(%d %c)", i, ch)
	}
	fmt.Println("11")

	fmt.Println(strings.Fields("hello world"))

}
